<template>
  <div class="container">
    <el-dialog
      class="addlog"
      title="新增文章"
      :visible.sync="addInterviewShow"
      width="60%"
      :before-close="addHandleClose"
    >
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="文章标题" prop="title" class="article-title">
          <el-input v-model="ruleForm.title" placeholder="请输入文章标题"></el-input>
        </el-form-item>
        <el-form-item label="文章内容" prop="articleBody">
          <quill-editor v-model="ruleForm.articleBody"></quill-editor>
        </el-form-item>
        <el-form-item label="视频地址" prop="videoURL">
          <el-input v-model="ruleForm.videoURL" class="videostyle" placeholder="请输入视频地址"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addHandleClose">取 消</el-button>
        <el-button type="primary" @click="addArticle">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { add } from '@/api/hmmm/articles'
export default {
  data() {
    return {
      rules: {
        title: [{ required: true, message: '请输入文章标题', trigger: 'blur' }],
        articleBody: [{ required: true, message: '请输入文章内容', trigger: 'blur' }],
      },
    }
  },
  props: {
    addInterviewShow: {
      type: Boolean,
    },
    ruleForm: {
      type: Object,
    },
  },
  methods: {
    addHandleClose() {
      this.$emit('closeAddDialog')
      this.ruleForm.title = ''
      this.ruleForm.articleBody = ''
      this.ruleForm.videoURL = ''
      this.$refs.ruleForm.resetFields()
    },
    async addArticle() {
      if (
        this.ruleForm.title == '' ||
        this.ruleForm.articleBody == '' ||
        this.ruleForm.videoURL == ''
      ) {
        this.$message('请输入数据')
        return
      }
      await add(this.ruleForm)
      // 添加成功后的提示
      this.$message.success('添加成功')
      this.$emit('getList')
      // this.getTableData()
      this.$emit('closeAddDialog')
      this.ruleForm.title = ''
      this.ruleForm.articleBody = ''
      this.ruleForm.videoURL = ''
    },
  },
}
</script>

<style scoped lang="less">
.el-input {
  width: 200px;
}
.el-option {
  margin-right: 5px;
}
.el-select {
  margin-right: 10px;
}
.tops {
  margin-bottom: 10px;
}
.el-alert--info {
  margin-bottom: 8px;
}
.el-pagination {
  float: right;
  margin-top: 8px;
}
.ql-align-center img {
  width: 600px !important;
}
.ql-editor {
  min-height: 280px;
}
.el-table__row i {
  color: blue;
}
.article-title .el-input  {
  width: 770px !important;
}
.videostyle {
  width: 100%;
}
/deep/.ql-container.ql-snow {
  height: 300px;
}
</style>
